package com.mobisys.live.util;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

/**
 * Created by zhuo on 2018-01-23.
 * 校验输入
 */
public class ValidationUtil {

    /**
     * 用于获取校验时候的详细错误信息
     * @param bindingResult
     * @return
     */
    public static String getValidationInfo(BindingResult bindingResult){
        StringBuilder stringBuilder=new StringBuilder(" : ");

        for (FieldError fieldError : bindingResult.getFieldErrors()) {
            stringBuilder.append(fieldError.getDefaultMessage()+" 当前为："+fieldError.getRejectedValue());
        }

        return stringBuilder.toString();
    }
}
